ValidatedEntityAttribute
A validated Pairing of an EntityAttribute and a corresponding EntityAttributeModifier
ValidatedEntityAttribute has a private constructor, use Builder to create one
Author
fzzyhmstrs
Since
0.3.1
See also
Samples
import com.google.common.collect.ArrayListMultimap
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedEntityAttribute
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIngredient
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedTagKey
import net.minecraft.entity.attribute.EntityAttribute
import net.minecraft.entity.attribute.EntityAttributeModifier
import net.minecraft.recipe.Ingredient
import net.minecraft.registry.tag.BlockTags
import net.minecraft.registry.tag.ItemTags
import net.minecraft.util.Identifier
fun main() {
//sampleStart
// a Validated entity attrbute/entity attribute modifier pair
// the builder does not accept an EntityAttribute because it needs to serialize them,
// and the attribute might not be available at serialization time in the registry
// lockAttribute lets you constrain the attribute to the one chosen in the builder (Max Health in this case_
val exampleValidatedAttribute = ValidatedEntityAttribute.Builder("generic.max_health", true)
// supply a UUID and name, otherwise generic ones will be used for you
.id(Identifier.of("my_mod", "my_example_attribute"))
//set amount, and optionally provide a range restriction
.amount(1.0, 0.0, 8.0)
//set the operation for the modifier, and optionally lock the modifier to the operation chosen
.operation(EntityAttributeModifier.Operation.ADD_VALUE, true)
//build! gets you a ValidatedEntity Attribute
.build()
//easily add to an attribute map in e.g. Item#getAttributeModifiers using addToMap()
val attributeMap: ArrayListMultimap<EntityAttribute, EntityAttributeModifier> = ArrayListMultimap.create()
exampleValidatedAttribute.addToMap(attributeMap)
//if you need the modifier for something else, use attributeModifier()
val myModifier: EntityAttributeModifier = exampleValidatedAttribute.getModifier()
//sampleEnd
}
Types
A ValidatedEntityAttribute builder
A holder of entity attribute and modifier information. This is a class internal to ValidatedEntityAttribute, made public by necessity. In most cases, it's not correct to be directly interacting with this.
Functions
sets the underlying EntityAttributeInstanceHolder. Consider another method of interaction with this validation before a raw accept() call.
Attaches a listener to this field. This listener will be called any time the field is written to ("set"). accept
, validateAndSet
, setAndUpdate
and so on will all call the listener.
adds the stored Attribute and its modifier to a passed Attribute Component builder
adds the stored Attribute and its modifier to a passed Attribute Component builder
Provides a Codec representing the value type of this validation, backed by the validators within as applicable
Creates a deep copy of the stored value and returns it
The translated Text description from the descriptionKey. Falls back to an empty string so no tooltip is rendered.
translation key of this Translatable's description. the "description" in-game, the descriptions Enchantment Descriptions adds to enchantment tooltips are a good example.
gets the underlying EntityAttributeInstanceHolder. Consider another method of interaction with this validation before a raw get() call.
Provides this validations default value
builds and returns the EntityAttributeModifier associated with this validation
Whether this Translatable has a valid description
Whether this Translatable has a valid translation
creates a deep copy of this ValidatedEntityAttribute
Maps this validation to a new convertible type. The default value will be applied from this delegates current storedValue
Maps this validation to a new convertible type.
Convert this field to a ValidatedCondition using the provided validation as a supplier. The provided condition (and any others you append) must pass for the stored value to be provided, otherwise the fallback will be supplied.
Convert this field to a ValidatedCondition. The provided condition (and any others you append) must pass for the stored value to be provided, otherwise the fallback will be supplied.
Convert this field to a ValidatedCondition using the provided scope with a default boolean provider. The provided condition (and any others you append) must pass for the stored value to be provided, otherwise the fallback will be supplied. The provided scope must point to a valid boolean config scope otherwise the initial condition will never pass.
wraps the provided values into a ValidatedList with this field as validation
wraps the provided collection into a ValidatedList with this field as validation
wraps the provided values into a ValidatedSet with this field as validation
wraps the provided collection into a ValidatedSet with this field as validation
The translated Text name from the translationKey. Falls back to the implementing classes Simple Name (non-translated)
translation key of this Translatable. the "name" in-game
updates this validation with new EntityAttributeModifier values
updates this validation with a new double value
A setter method for the storedValue that first validates the value being set and then stores the post-validation result.